package com.shcd.controller;

import com.shcd.service.ExcelDownloadService;
import com.shcd.tools.ExcelTools;
import org.apache.ibatis.annotations.Mapper;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;

@RestController
@RequestMapping("LogVisualization")
public class ExcelDownloadController {

    private final ExcelDownloadService excelDownloadService;

    @Autowired
    public ExcelDownloadController(ExcelDownloadService excelDownloadService) {
        this.excelDownloadService = excelDownloadService;
    }

    @GetMapping("/ExcelDownload")
    public void ExcelDownload(HttpServletResponse response) throws IOException, ParseException {
        excelDownloadService.excelDownload(response);
    }

    /**
     * excel 页面预览
     * @param response
     * @throws IOException
     * @throws ParseException
     */
    @RequestMapping(value="viewExcel",method = RequestMethod.GET)
    public void excelView(HttpServletResponse response)throws IOException, ParseException{
        HSSFWorkbook work = excelDownloadService.getExcelHssfWorkbook();
        ExcelTools.writToAjax(response,work);
    }
}
